package com.d0318.homework;

public class Meeting implements Runnable{
    static int id=1;
    static Object object = new Object();
    @Override
    public void run() {
        p();
    }
    public  void p(){
        while (id <= 30){
            synchronized (object){
                int num = (int)(Math.random()*30);
                System.out.println(id +"号员工"+Thread.currentThread().getName()+"进入，奖牌号"+num);
                id ++;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        Thread t1=new Thread(new Meeting(),"前门");
        Thread t2=new Thread(new Meeting(),"后门");
        t1.start();
        t2.start();
    }
}
